package com.hsl.study.config;

import com.hsl.study.service.ChatAssistant;
import dev.langchain4j.service.AiServices;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;

import java.time.Duration;

/**
 * @Author: hsl
 * @CreateTime: 2025-03-12  19:04
 */
@Configuration
public class ChatLangChainModelConfig {
    @Bean
    public StreamingChatLanguageModel ChatLanguageModel() {
        return OpenAiStreamingChatModel.builder()
                .apiKey(System.getenv("LANGCHAIN_QIANWEN"))
                .modelName("qwen-turbo-0624")
                .timeout(Duration.ofSeconds(10))
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .build();
    }
    @Bean
    public ChatAssistant chatAssistant(StreamingChatLanguageModel chatLanguageModel) {
        return AiServices.create(ChatAssistant.class, chatLanguageModel);
    }
}
